<template>
  <div>
    <p>投诉内容：{{newSuggest.content}}</p>
    <p>投诉时间:{{newSuggest.suggestTime}}</p>
    <br>
    <p>您的回复：</p>
    <el-input v-model="newSuggest.reply"></el-input>
    <br><br>
    <div id="action">
      <el-button type="info"
                 size="mini"
                 @click="cancel">取消</el-button>
      <el-button type="danger"
                 size="mini"
                 @click="commit">确定</el-button>
    </div>
  </div>
</template>

<script>
export default {
  props: {
    suggest: {},//用来接收父组件传过来的数据
  },
  //当组件创建完毕之后自动调用此方法
  mounted () {
    console.log("update组件创建完毕");
    //js深拷贝
    //stringify 转换成json格式的字符串
    //parse 将字符串转换成JSON数据  对象
    this.newSuggest = JSON.parse(JSON.stringify(this.suggest));
  },
  data () {
    return {
      newSuggest: {}//副本
    }
  },
  methods: {
    cancel () {
      //通知父组件关闭对话框
      this.$emit("closedialog", { result: false, data: {} });
    },
    //确定，将数据返回父组件
    commit () {
      //获取当前回复时间
      let date = new Date();
      let seperator1 = "-";
      let seperator2 = ":";
      let month = date.getMonth() + 1;
      let strDate = date.getDate();
      if (month >= 1 && month <= 9) {
        month = "0" + month;
      }
      if (strDate >= 0 && strDate <= 9) {
        strDate = "0" + strDate;
      }
      let currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate
        + " " + date.getHours() + seperator2 + date.getMinutes()
        + seperator2 + date.getSeconds();

      //修改回复时间与是否处理
      this.newSuggest.replyTime = currentdate;
      this.newSuggest.result = "已处理";
      //关闭对话框并提交数据
      this.$emit("closedialog", { result: true, data: this.newSuggest });
    }
  }
}
</script>

<style scoped>
#action {
  position: absolute;
  right: 10px;
  bottom: 10px;
}
</style>